import QtQuick 1.1
import com.nokia.meego 1.0

Item{
    property int value:0
    property int minValue:0
    property int maxValue:10
    property int step:1
    property int divider:1

    property real realValue:value/divider

    property bool autoPlus: false
    property bool autoMinus: false

    height: 80

    RoundButton{
        id: buttonMinus
        anchors.left: parent.left

        width: 80; height: 80;
        imgSource: "qrc:/images/minus.png"
        imgPressedSource: "qrc:/images/minus2.png"
        imgDisabledSource: "qrc:/images/minus3.png"

        isEnabled: value>=minValue+step

        onButtonReleased: autoMinus=false

        function buttonClicked(){
            minusClicked()
        }

        Timer {running: buttonMinus.pressed; interval: 350; onTriggered: autoMinus=true}
        Timer {running: autoMinus; interval: 60; repeat: true; onTriggered: minusClicked()}
    }

    TextField{
        id: textValue
        enabled: false
        width: 160
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        text: value/divider
        validator: divider==1?intValidator:doubleValidator

        IntValidator{id: intValidator; bottom: minValue; top: maxValue}
        DoubleValidator{id: doubleValidator; bottom: minValue/divider; top: maxValue/divider}

        /*
        onTextChanged: {
            value = textValue.text
            console.log = value
        }
        */
    }



    RoundButton{
        id: buttonPlus

        anchors.right: parent.right

        width: 80; height: 80;
        imgSource: "qrc:/images/plus.png"
        imgPressedSource: "qrc:/images/plus2.png"
        imgDisabledSource: "qrc:/images/plus3.png"

        isEnabled: value<=maxValue-step

        onButtonReleased: autoPlus=false

        function buttonClicked(){
            plusClicked()
        }

        Timer {running: buttonPlus.pressed; interval: 350; onTriggered: autoPlus=true}
        Timer {running: autoPlus; interval: 60; repeat: true; onTriggered: plusClicked()}

    }
    function minusClicked(){
        value-=step
        if (value<minValue+step) autoMinus=false
    }

    function plusClicked(){
        value+=step
        if (value>maxValue-step) autoPlus=false
    }
}
